package com.mylove.textprogressbar;

import android.text.InputType;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

/**
 * @author myLove
 * @time 2017/12/27 21:36
 * @e-mail love@yanyi.red
 * @overview
 */

public class MainActivity extends BaseActivity implements View.OnClickListener {

    private TextBarView barView;
    private EditText edit1;
    private EditText edit2;
    private Button but;

    @Override
    protected int setContentView() {
        return R.layout.main_activity;
    }

    @Override
    protected void init() {
        barView = $(R.id.bar);
        edit1 = $(R.id.edit);
        edit2 = $(R.id.edit2);
        edit2.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
        but = $(R.id.but);
        barView.setNum(100, 150, 400)
                .setSize(460)
                .setColor(new int[]{getResources().getColor(R.color.color_green),
                        getResources().getColor(R.color.colorAccent),
                        getResources().getColor(R.color.colorPrimary)})
                .setMsg("", "8折", "5折")
                .setTime(4)
                .start();
        but.setOnClickListener(MainActivity.this);
    }

    @Override
    public void onClick(View v) {
        String str1 = edit1.getText().toString();
        String str2 = edit2.getText().toString();
        float size = Float.valueOf(TextUtils.isEmpty(str2) ? "50" : str2);
        int time = Integer.valueOf(TextUtils.isEmpty(str1) ? "10" : str1);
        barView.stop();
        try {
            Thread.sleep(100);
        } catch (Exception e) {
            e.printStackTrace();
        }
        barView.setTime(time)
                .setSize(size)
                .start();
        v(size, time);
    }
}
